﻿using System;
using System.Collections.Generic;
using Terraria.Social.Base;
using Terraria.Social.Steam;

namespace Terraria.Social
{
	// Token: 0x0200012E RID: 302
	public static class SocialAPI
	{
		// Token: 0x170000DF RID: 223
		// (get) Token: 0x06000D13 RID: 3347 RVA: 0x0000D261 File Offset: 0x0000B461
		public static SocialMode Mode
		{
			get
			{
				return SocialAPI._mode;
			}
		}

		// Token: 0x06000D14 RID: 3348 RVA: 0x003F6F10 File Offset: 0x003F5110
		public static void Initialize(SocialMode? mode = null)
		{
			if (mode == null)
			{
				mode = new SocialMode?(SocialMode.None);
				mode = new SocialMode?(SocialMode.Steam);
			}
			SocialAPI._mode = mode.Value;
			SocialAPI._modules = new List<ISocialModule>();
			SocialMode mode2 = SocialAPI.Mode;
			if (mode2 == SocialMode.Steam)
			{
				SocialAPI.LoadSteam();
			}
			foreach (ISocialModule socialModule in SocialAPI._modules)
			{
				socialModule.Initialize();
			}
		}

		// Token: 0x06000D15 RID: 3349 RVA: 0x003F6FA0 File Offset: 0x003F51A0
		public static void Shutdown()
		{
			SocialAPI._modules.Reverse();
			foreach (ISocialModule socialModule in SocialAPI._modules)
			{
				socialModule.Shutdown();
			}
		}

		// Token: 0x06000D16 RID: 3350 RVA: 0x003F6FFC File Offset: 0x003F51FC
		private static T LoadModule<T>() where T : ISocialModule, new()
		{
			T t = (default(T) == null) ? Activator.CreateInstance<T>() : default(T);
			SocialAPI._modules.Add(t);
			return t;
		}

		// Token: 0x06000D17 RID: 3351 RVA: 0x0000D268 File Offset: 0x0000B468
		private static T LoadModule<T>(T module) where T : ISocialModule
		{
			SocialAPI._modules.Add(module);
			return module;
		}

		// Token: 0x06000D18 RID: 3352 RVA: 0x0000D27B File Offset: 0x0000B47B
		private static void LoadSteam()
		{
			SocialAPI.LoadModule<CoreSocialModule>();
			SocialAPI.Friends = SocialAPI.LoadModule<Terraria.Social.Steam.FriendsSocialModule>();
			SocialAPI.Achievements = SocialAPI.LoadModule<Terraria.Social.Steam.AchievementsSocialModule>();
			SocialAPI.Cloud = SocialAPI.LoadModule<Terraria.Social.Steam.CloudSocialModule>();
			SocialAPI.Overlay = SocialAPI.LoadModule<Terraria.Social.Steam.OverlaySocialModule>();
			SocialAPI.Network = SocialAPI.LoadModule<NetClientSocialModule>();
		}

		// Token: 0x040011A1 RID: 4513
		private static SocialMode _mode;

		// Token: 0x040011A2 RID: 4514
		public static Terraria.Social.Base.FriendsSocialModule Friends;

		// Token: 0x040011A3 RID: 4515
		public static Terraria.Social.Base.AchievementsSocialModule Achievements;

		// Token: 0x040011A4 RID: 4516
		public static Terraria.Social.Base.CloudSocialModule Cloud;

		// Token: 0x040011A5 RID: 4517
		public static Terraria.Social.Base.NetSocialModule Network;

		// Token: 0x040011A6 RID: 4518
		public static Terraria.Social.Base.OverlaySocialModule Overlay;

		// Token: 0x040011A7 RID: 4519
		private static List<ISocialModule> _modules;
	}
}
